package dao;

import entity.Admin;
import org.apache.commons.dbutils.BasicRowProcessor;
import org.apache.commons.dbutils.GenerousBeanProcessor;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import utils.DBUtil;

import java.sql.SQLException;
import java.util.List;

public class AdminDao {
    QueryRunner queryRunner = new QueryRunner(DBUtil.getDataSource());

    //可以将下划线命名的改为驼峰命名
    BeanListHandler<Admin> blh = new BeanListHandler<>(
            Admin.class, new BasicRowProcessor(new GenerousBeanProcessor()));

    /**
     * 查询用户
     */
    public List<Admin> query(String sql, Object... params){
        try {
            List<Admin> admins = queryRunner.query(sql, blh, params);
            return admins;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
